﻿Imports System.ComponentModel
Public Class C_SQL
#Region "初始化"
    Implements IDisposable

    Dim CN As DCM_Http.DCM_CN
    Public Sub New(CN As DCM_Http.DCM_CN)
        Me.CN = CN
    End Sub
    Public Function 自己写() As Object
        Throw New Exception("我没试验过,自己写吧!")
    End Function
#Region "IDisposable Support"
    Private disposedValue As Boolean ' 要检测冗余调用

    ' IDisposable
    Protected Overridable Sub Dispose(disposing As Boolean)
        If Not disposedValue Then
            If disposing Then
                ' TODO: 释放托管状态(托管对象)。
                Try
                    cn.Dispose()
                Catch ex As Exception

                End Try
            End If

            ' TODO: 释放未托管资源(未托管对象)并在以下内容中替代 Finalize()。
            ' TODO: 将大型字段设置为 null。
        End If
        disposedValue = True
    End Sub

    ' TODO: 仅当以上 Dispose(disposing As Boolean)拥有用于释放未托管资源的代码时才替代 Finalize()。
    'Protected Overrides Sub Finalize()
    '    ' 请勿更改此代码。将清理代码放入以上 Dispose(disposing As Boolean)中。
    '    Dispose(False)
    '    MyBase.Finalize()
    'End Sub

    ' Visual Basic 添加此代码以正确实现可释放模式。
    Public Sub Dispose() Implements IDisposable.Dispose
        ' 请勿更改此代码。将清理代码放入以上 Dispose(disposing As Boolean)中。
        Dispose(True)
        ' TODO: 如果在以上内容中替代了 Finalize()，则取消注释以下行。
        ' GC.SuppressFinalize(Me)
    End Sub
#End Region
#End Region
#Region "Insert"
    Public Function Insert(TBname As String, ColNames() As String, Values() As String, Optional TimeOut As Integer = 30) As String
        Dim sqlstr = DCM.SQLSr_Insert(TBname, ColNames, Values, CN.DataBaseType)
        Return Insert(sqlstr, TimeOut)
    End Function
    Public Function Insert(SQLStr As String, Optional TimeOut As Integer = 30) As String
        Select Case CN.DataBaseType
            Case DCM.DCM_Enum.Enum_数据库类型.SQLServer
                Dim CN_this As New DCM_SQL_SQLServer.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.Insert(SQLStr, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.SQLite
                Dim CN_this As New DCM_SQL_Sqlite.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.Insert(SQLStr, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.Oracle
                Dim CN_this As New DCM_SQL_Oracle.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.Insert(SQLStr, TimeOut)
            Case Else
                Return 自己写()
        End Select
    End Function

    Public Function Insert(TBname As String, ColNames() As String, Values() As Object, Optional TimeOut As Integer = 30) As String
        Select Case CN.DataBaseType
            Case DCM.DCM_Enum.Enum_数据库类型.SQLServer
                Dim CN_this As New DCM_SQL_SQLServer.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.Insert(TBname, ColNames, Values, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.SQLite
                Dim CN_this As New DCM_SQL_Sqlite.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.Insert(TBname, ColNames, Values, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.Oracle
                Dim CN_this As New DCM_SQL_Oracle.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.Insert(TBname, ColNames, Values, TimeOut)
            Case Else
                Return 自己写()
        End Select
    End Function
#End Region
#Region "GetDataTable"
    Public Function GetDataTable(ByVal Table_Name As String,
                Optional ByVal Filterstring As String = Nothing,
                Optional ByVal TopNum As Integer = -1,
                Optional ByVal ColumnsNames() As String = Nothing,
                Optional ByVal OrderOrGroupstring As String = "",
                Optional TimeOut As Integer = 300) As DataTable
        Dim SQLStr = DCM.SQLStr_Select(Table_Name, Filterstring, TopNum, ColumnsNames, OrderOrGroupstring, CN.DataBaseType)
        Return GetDataTable(SQLStr, TimeOut)
    End Function
    Public Function GetDataTable(SQLStr As String, Optional TimeOut As Integer = 300) As DataTable
        Select Case CN.DataBaseType
            Case DCM.DCM_Enum.Enum_数据库类型.SQLServer
                Dim CN_this As New DCM_SQL_SQLServer.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.GetDataTable(SQLStr, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.SQLite
                Dim CN_this As New DCM_SQL_Sqlite.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.GetDataTable(SQLStr, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.Oracle
                Dim CN_this As New DCM_SQL_Oracle.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.GetDataTable(SQLStr, TimeOut)
            Case Else
                Return 自己写()
        End Select
    End Function
#End Region
#Region "GetObject"
    Public Function GetObject(SQLStr As String, Optional TimeOut As Integer = 30) As Object
        Select Case CN.DataBaseType
            Case DCM.DCM_Enum.Enum_数据库类型.SQLServer
                Dim CN_this As New DCM_SQL_SQLServer.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.GetObject(SQLStr, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.SQLite
                Dim CN_this As New DCM_SQL_Sqlite.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.GetObject(SQLStr, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.Oracle
                Dim CN_this As New DCM_SQL_Oracle.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.GetObject(SQLStr, TimeOut)
            Case Else
                Return 自己写()
        End Select
    End Function
#End Region
#Region "GetDataSet"
    Public Function GetDataSet(SQLStr As String, Optional TimeOut As Integer = 30) As Object
        Select Case CN.DataBaseType
            Case DCM.DCM_Enum.Enum_数据库类型.SQLServer
                Dim CN_this As New DCM_SQL_SQLServer.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.GetDataSet(SQLStr, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.SQLite
                Dim CN_this As New DCM_SQL_Sqlite.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.GetDataSet(SQLStr, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.Oracle
                Dim CN_this As New DCM_SQL_Oracle.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.GetDataSet(SQLStr, TimeOut)
            Case Else
                Return 自己写()
        End Select
    End Function
#End Region
#Region "Effect"
    Public Function Effect(SQLStr As String, Optional TimeOut As Integer = 30) As Object
        Select Case CN.DataBaseType
            Case DCM.DCM_Enum.Enum_数据库类型.SQLServer
                Dim CN_this As New DCM_SQL_SQLServer.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.effect(SQLStr, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.SQLite
                Dim CN_this As New DCM_SQL_Sqlite.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.effect(SQLStr, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.Oracle
                Dim CN_this As New DCM_SQL_Oracle.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.effect(SQLStr, TimeOut)
            Case Else
                Return 自己写()
        End Select
    End Function
#End Region
#Region "BctchAdd_To_DateBase"
    Public Function BctchAdd_To_DateBase(合并提交SQLstr As String, DT_This As DataTable, TBName_This As String, Optional TimeOut As Integer = 300) As Integer
        Select Case CN.DataBaseType
            Case DCM.DCM_Enum.Enum_数据库类型.SQLServer
                Dim CN_this As New DCM_SQL_SQLServer.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.BctchAdd_To_DateBase(合并提交SQLstr, DT_This, TBName_This, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.SQLite
                Dim CN_this As New DCM_SQL_Sqlite.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.BctchAdd_To_DateBase(合并提交SQLstr, DT_This, TBName_This, TimeOut)
            Case DCM.DCM_Enum.Enum_数据库类型.Oracle
                Dim CN_this As New DCM_SQL_Oracle.C_SQL(DCM.GetCN_Connect(CN.DCM_SQLServer_DataBase))
                Return CN_this.BctchAdd_To_DateBase(合并提交SQLstr, DT_This, TBName_This, TimeOut)
            Case Else
                Return 自己写()
        End Select
    End Function
#End Region
End Class
